package com.mage.servlet;

import com.mage.bean.PageBean;
import com.mage.bean.User;
import com.mage.dao.UserDao;
import com.mage.dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/UserDetailServlet")
public class UserDetailServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public UserDetailServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {

            int userid = Integer.parseInt(request.getParameter("userid"));
            int usertype = Integer.parseInt(request.getParameter("usertype"));
            UserDao service = new UserDaoImpl();
            User user = service.findUserById(userid);
            request.setAttribute("user", user);
            //3. 跳转界面。
            if (usertype == -1){
                request.getRequestDispatcher("/Super/VipChongzhi.jsp").forward(request, response);
            }else{
                request.getRequestDispatcher("/Super/User_chongzhi.jsp").forward(request, response);
            }

        }catch (Exception e) {
            // TODO: handle exception
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
